/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.jm.financeiro.entity;

import br.jm.financeiro.filter.ConfiguraCampoAnnotation;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.validation.constraints.Size;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

/**
 *
 * @author joao
 */
@Entity
@Table(name = "proposta_valor", catalog = "salao", schema = "public")
@NamedQueries({
    @NamedQuery(name = "PropostaValor.findAll", query = "SELECT p FROM PropostaValor p")})
public class PropostaValor implements Serializable, Comparable<PropostaValor> {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "proposta_valor_id_proposta_valor_seq")
    @SequenceGenerator(name = "proposta_valor_id_proposta_valor_seq", sequenceName = "proposta_valor_id_proposta_valor_seq", initialValue = 1, allocationSize = 1)
    @Basic(optional = false)
    @Column(name = "id_proposta_valor", nullable = false)
    private Integer idPropostaValor;
    @Column(name = "dsc_etapa", length = 200)
    private String dscEtapa;
    @Size(max = 50)
    @Column(name = "dsc_assunto", length = 50)
    private String dscAssunto;
    @Column(name = "vlr_etapa", precision = 18, scale = 2)
    private BigDecimal vlrEtapa;
    @ConfiguraCampoAnnotation(tipo = "integer", pesquisa = "idEmpresa", campo = "id_Empresa", nomeTabela = "proposta", nomeTabelJoin = "Empresa")
    @Column(name = "num_etapa")
    private Integer numEtapa;
    
    @ConfiguraCampoAnnotation(tipo = "date", pesquisa = "datOs", campo = "dat_Os", nomeTabela = "proposta_valor", nomeTabelJoin = "Proposta")
    @JoinColumn(name = "id_proposta", referencedColumnName = "id_proposta", nullable = true)
    @ManyToOne(optional = true, fetch = FetchType.EAGER)
    private Proposta idProposta;
    
    @ConfiguraCampoAnnotation(tipo = "integer", pesquisa = "idEmpreendimento", campo = "id_empreendimento", nomeTabela = "proposta_valor", nomeTabelJoin = "propposta")
    @LazyCollection(LazyCollectionOption.FALSE)
    @org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idPropostaValor")
    private List<PropostaValorPerc> propostaValorPercList;

    public PropostaValor() {
    }

    public PropostaValor(Integer idPropostaValor) {
        this.idPropostaValor = idPropostaValor;
    }

    public Integer getIdPropostaValor() {
        return idPropostaValor;
    }

    public void setIdPropostaValor(Integer idPropostaValor) {
        this.idPropostaValor = idPropostaValor;
    }

    public String getDscEtapa() {
        return dscEtapa;
    }

    public void setDscEtapa(String dscEtapa) {
        this.dscEtapa = dscEtapa;
    }

    public BigDecimal getVlrEtapa() {
        return vlrEtapa;
    }

    public void setVlrEtapa(BigDecimal vlrEtapa) {
        this.vlrEtapa = vlrEtapa;
    }
    public Proposta getIdProposta() {
        return idProposta;
    }

    public void setIdProposta(Proposta idProposta) {
        this.idProposta = idProposta;
    }

    public String getDscAssunto() {
        return dscAssunto;
    }

    public void setDscAssunto(String dscAssunto) {
        this.dscAssunto = dscAssunto;
    }

    public List<PropostaValorPerc> getPropostaValorPercList() {
        return propostaValorPercList;
    }

    public void setPropostaValorPercList(List<PropostaValorPerc> propostaValorPercList) {
        this.propostaValorPercList = propostaValorPercList;
    }

    public Integer getNumEtapa() {
        return numEtapa;
    }

    public void setNumEtapa(Integer numEtapa) {
        this.numEtapa = numEtapa;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idPropostaValor != null ? idPropostaValor.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof PropostaValor)) {
            return false;
        }
        PropostaValor other = (PropostaValor) object;
        if ((this.idPropostaValor == null && other.idPropostaValor != null) || (this.idPropostaValor != null && !this.idPropostaValor.equals(other.idPropostaValor))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "br.jm.financeiro.entity.PropostaValor[ idPropostaValor=" + idPropostaValor + " ]";
    }

    @Override
    public int compareTo(PropostaValor o) {
        int valor = numEtapa.compareTo(o.numEtapa);
        return (valor != 0 ? valor : 1);
    }
}
